using UnityEngine;
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class client_cs : MonoBehaviour {

	// Use this for initialization
    //CSdConnector_TCP connector = new CSdConnector_TCP();
    /**/
    //CSdConnector_TCP mcli = new CSdConnector_TCP();
    CSdPeer_UDP mcli = new CSdPeer_UDP();
    void Start () {
        CMyProtocolMgrClient pm = new CMyProtocolMgrClient();
        mcli.Connect("192.168.43.255", 9999, pm);
		//mcli.Connect("10.240.70.255", 9999, pm);
	}

    static int i = 1;
    void Sendlog()
    {
        PKT_GSCLI_TRIGGER_ACTION_ACK p = new PKT_GSCLI_TRIGGER_ACTION_ACK();
        p.Para1 = 1;
        p.Para2 = 2;
        p.Para3 = "3hello";
        p.Para4 = "4world";
        p.TriggerActionID = 5;
        p.TriggerEntityID = 6;
        p.TriggerID = 7;
        p.TriggerRole = 8888;
        PKT_CLIGS_TRIGGER_DAMAGE_REQ ctdr = new PKT_CLIGS_TRIGGER_DAMAGE_REQ();
        ctdr.TriggerEntityID = 99;
        ctdr.TriggerID = 88;

        mcli.SendProtocol_Real(ctdr, (ushort)MSGID.CLIGS_TRIGGER_DAMAGE_REQ);
        mcli.SendProtocol_Real(p, (ushort)MSGID.GSCLI_TRIGGER_ACTION_ACK);
        //connector.Send("hello world");
        //mcli.Send("GET /:8000 HTTP/1.1 \n\n\n");
    }
    void Update()
    {
        try
        {
            mcli.Run();
            //string recvstr = connector.Recv();
            //if (recvstr.Length > 0)
            //{
            //    print("client recv " + recvstr);
            //}
        }
        catch (System.Exception ex)
        {
        	
        }
    }
    void OnGUI()
    {
        GUI.BeginGroup(new Rect(Screen.width / 2, 0, Screen.width, 300f));
        // All rectangles are now adjusted to the group. (0,0) is the topleft corner of the group.

        // We'll make a box so you can see where the group is on-screen.
        GUI.Box(new Rect(0, 0, 300, 300), "client");
        if (GUI.Button(new Rect(10.0f, 40.0f, 150.0f, 30.0f), "send to server"))
        {
            //ClientRun();
            Sendlog();
        }

        // End the group we started above. This is very important to remember!
        GUI.EndGroup();
    }
}
